/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package ejbs;

import com.stefanini.persistencia.Usuario;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.ejb.LocalBean;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

/**
 *
 * @author EDWIN
 */

@LocalBean
@Stateless
public class UserManager {
    
    @PersistenceContext
    private EntityManager em;
    
    public Usuario verificarLogin(String usuario, String password){
        try{
          StringBuilder query = new StringBuilder();
          query.append("SELECT u FROM Usuario u ");
          query.append("WHERE u.username = :USERNAME ");
          query.append(" AND u.password = :PASSWORD ");
          
 
          Query q = em.createQuery(query.toString(),Usuario.class);
          q.setParameter("USERNAME", usuario);
          q.setParameter("PASSWORD", password);
          return (Usuario)q.getSingleResult();
        } catch (Exception e){
            Logger.getLogger(UserManager.class.getName()).log(Level.SEVERE,"ERROR AL BABLABLA");
        }
        return null;
    }
    
}
